<template>
	<view class="container">
		<u-cell-group>
			<view @tap.stop="toPage" data-url="/pageSetting/remind/index"><u-cell-item title="投诉与举报"></u-cell-item></view>
			<u-cell-item title="拉入黑名单" :arrow="false" hover-class="none">
				<!--  -->
				<u-switch active-color="#F85962" slot="right-icon" v-model="inBlack" :loading="loadBlack" @change="onBlackHandle"></u-switch>
			</u-cell-item>
		</u-cell-group>
	</view>
</template>

<script>
export default {
	data() {
		return {
			inBlack: false,
			loadBlack: true,
			user_id: null
		};
	},
	async onLoad(options) {
		this.user_id = options.user_id;
		await this.getMemberDetail();
	},
	methods: {
		async getMemberDetail() {
			try {
				const res = await this.$u.api.getOtherUserDetail(this.user_id);
				const { match } = res.data;
				this.inBlack = !!match.inblack;
				this.loadBlack = false;
			} catch (e) {
				this.loadBlack = false;
			}
		},
		onBlackHandle(value) {
			if (value) {
				uni.showModal({
					title: '提示',
					content: '拉黑后，将无法在动态、卡片中看到对方，也无法收到对方的消息，对方也将无法查看你的信息',
					success: result => {
						this.loadBlack = true;
						if (result.confirm) {
							this.$u.api
								.inBlackList(this.user_id)
								.then(res => {
									this.loadBlack = false;
								})
								.catch(e => {
									this.inBlack = false;
									this.loadBlack = false;
								});
						}

						if (result.cancel) {
							this.inBlack = false;
							this.loadBlack = false;
						}
					}
				});
			} else {
				this.loadBlack = true;
				this.$u.api
					.outBlackList(this.user_id)
					.then(res => {
						this.loadBlack = false;
					})
					.catch(e => {
						this.inBlack = true;
						this.loadBlack = false;
					});
			}
		}
	}
};
</script>

<style></style>
